home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / comm / misc / S5-Trans.lha / S5-copydir < prev    next >
Encoding:
Text File  |  1999-04-12  |  1.9 KB  |  72 lines

  1. /*
  2. $VER: S5-copydir 0.1 (9.4.99)
  3. by Neil Bothwick
  4. Uses S5-trans to copy a complete Psion5 directory
  5. */
  6.  
  7. /* ;;; Initialise */
  8. ScriptName = 'S5-copydir'
  9. options results
  10. address command
  11. if ~show('L','rexxsupport.library') then do
  12.     if ~addlib('rexxsupport.library',0,-30,0) then call ExitMsg(ScriptName 'requires rexxsupport.library')
  13.     end
  14. if ~show('L','rexxdossupport.library') then do
  15.     if ~addlib('rexxdossupport.library',0,-30,0) then call ExitMsg(ScriptName 'requires rexxdossupport.library')
  16.     end
  17. 'which >NIL: s5-dir'
  18. if RC > 0 then call ExitMsg('This script needs the commands from S5-trans installed in your path')
  19. ;;;
  20. /* ;;; Read arguments */
  21. parse arg args
  22. Template = 'SOURCE/A,DEST/A'
  23. Usage = 'Usage: S5-copydir' template
  24. call ReadArgs(args,template)
  25. if RC > 0 then call ExitMsg(Usage)
  26. DirCount = 0
  27. ;;;
  28. /* ;;; Copy directory */
  29. call CopyDir(Source,Dest)
  30. exit
  31. ;;;
  32. /* ;;; Read and copy a directory */
  33. CopyDir: procedure expose DirCount
  34.     DirCount = DirCount + 1
  35.     Source = arg(1)
  36.     Dest = arg(2)
  37.     if right(Source,1) ~= '\' then Source = Source'\'
  38.     if ~exists(Dest) then do
  39.         'makedir "'Dest'"'
  40.         if RC > 0 then call ExitMsg('Could not create directory' Dest)
  41.         end
  42.     ext = DirCount
  43.     OutFile = 'T:S5-copydir.'ext
  44.     'S5-dir >'OutFile '"'Source'"'
  45.     if ~open(out||ext,OutFile,'R') then call ExitMsg('Failed to read temporary file')
  46.     do until eof(out||ext)
  47.         line = readln(out||ext)
  48.         if line = '' then iterate
  49.         /*say line*/
  50.         ItemName = subword(line,1,words(line) - 4)
  51.         ItemType = word(line,words(line) - 3)
  52.         ItemDate = subword(line,words(line) - 1)
  53.         if ItemType = 'Dir' then call CopyDir(Source||ItemName,AddPart(Dest,ItemName))
  54.         else do
  55.             say 'Copying' Source||ItemName'...'
  56.             'S5-get >NIL: "'Source||ItemName'"' '"'AddPart(Dest,ItemName)'"'
  57.             /*call delay(10)*/
  58.             'setdate >NIL:' '"'AddPart(Dest,ItemName)'"' ItemDate
  59.             end
  60.         end
  61.     call close(out||ext)
  62.     call delete(OutFile)
  63.     return
  64. ;;;
  65. /* ;;; Exit with a message */
  66. ExitMsg:
  67.     parse arg msg
  68.     say msg
  69.     if msg = Usage then exit
  70.     exit 10
  71. ;;;
  72.